Test Failed
Push — master ( e5fd7d...d295c6 )
by Andrew
08:39 queued 04:33
created

index.test.ts ➔ callback   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import fs from 'fs';
2
import path from 'path';
3
import {PluginCritical} from '../../index';
4
import {Plugin} from 'rollup';
5
import {expect, test } from 'vitest'
6
7
const testRoot = path.join(__dirname, '/');
8
const testOutputPath = path.join(testRoot, 'test_critical.min.css');
9
const expectedOutputPath = path.join(testRoot, 'index_critical.min.css');
10
11
const pluginConfig: CriticalPluginConfig = {
12
    criticalBase: testRoot,
13
    criticalUrl: testRoot,
14
    criticalPages: [
15
        {
16
            uri: 'index.html',
17
            template: 'test',
18
        }
19
    ],
20
    criticalConfig: {
21
        inline: false,
22
    },
23
};
24
25
test('`inline: false` Critical CSS generation', () => {
26
    function callback() {
27
            expect(fs.readFileSync(testOutputPath))
28
                .toEqual(fs.readFileSync(expectedOutputPath));
29
    }
30
    // Instantiate the Rollup plugin
31
    const plugin: Plugin = PluginCritical(pluginConfig, callback);
32
    // Call the plugin to generate critical css
33
    if (plugin && typeof plugin.writeBundle === 'function') {
34
        // @ts-ignore
35
        plugin.writeBundle({
36
            dir: testRoot,
37
        }, {
38
            chunk: {
39
                type: 'asset',
40
                fileName: 'style.css',
41
            }
42
        });
43
    }
44
});
45